package com.it.travel01.controller;


import com.it.travel01.service.FavoriteService;
import com.it.travel01.service.RouteService;
import com.it.travel01.vo.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("favorite")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;

    @Autowired
    private RouteService routeService;

    /**
     * 收藏回显功能
     * @param rid 查询详情路线id
     * @return
     */
    @RequestMapping("isFavoriteByRid")
    @ResponseBody
    public ResultInfo isFavoriteByRid(@RequestParam("rid")Integer rid) {
        return favoriteService.isFavoriteByRid(rid);
    }

    /**
     * 添加收藏
     * @param rid
     * @return
     */
    @RequestMapping("addFavorite")
    @ResponseBody
    public ResultInfo addFavorite(@RequestParam("rid")Integer rid) {
        return routeService.addFavorite(rid);
    }


    /**
     * 我的收藏展示
     * @param curPage
     * @return
     */
    @RequestMapping("findFavoriteByPage")
    @ResponseBody
    public ResultInfo findFavoriteByPage(@RequestParam(required = false,defaultValue = "1") Integer curPage) {
        return favoriteService.findFavoriteByPage(curPage);
    }
}
